package parser

import (
	"fmt"
	"log"
	"my-crawler/concurrence/engine"
	"my-crawler/concurrence/fetcher"
	"my-crawler/concurrence/task/gzh_comments_num/dao"
	common "my-crawler/pkg"
	"regexp"
)

//步骤1 获取comment_id
func GetCommentIdParser(content []byte, ReqData engine.ReqData) engine.ParserResult {
	var reg = regexp.MustCompile(`var comment_id = "(.*)" \|\| "(.*)" \* 1;`)
	cid := common.ExtractString(content, reg)
	fmt.Println(cid)
	res := engine.ParserResult{}

	//请求获取评论数接口
	id, ok := ReqData.Payload["id"]
	if !ok {
		log.Fatal("Not Found ID!")
	}
	reqData, header, reqUrl := dao.GetComment(id, cid)

	//追加请求
	res.Request = append(res.Request, engine.CrawlerRequest{
		ReqData:  engine.CreateReqData(header, reqData, reqUrl), //数据初始化
		HttpFunc: &fetcher.GetReq{},                             //请求
		Parser:   GetCommentsNumParser,
	})
	return res
}
